package org.dromara.nursing.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
// import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.nursing.domain.vo.StaffScheduleVo;
import org.dromara.nursing.domain.bo.StaffScheduleBo;
import org.dromara.nursing.service.IStaffScheduleService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 排班信息表
 *
 * @author Xue
 * @date 2025-04-01
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/nursing/staffSchedule")
public class StaffScheduleController extends BaseController {

    private final IStaffScheduleService staffScheduleService;

    /**
     * 查询排班信息表列表
     */
    // @SaCheckPermission("nursing:staffSchedule:list")
    @GetMapping("/list")
    public TableDataInfo<StaffScheduleVo> list(StaffScheduleBo bo, PageQuery pageQuery) {
        return staffScheduleService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出排班信息表列表
     */
    // @SaCheckPermission("nursing:staffSchedule:export")
    @Log(title = "排班信息表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(StaffScheduleBo bo, HttpServletResponse response) {
        List<StaffScheduleVo> list = staffScheduleService.queryList(bo);
        ExcelUtil.exportExcel(list, "排班信息表", StaffScheduleVo.class, response);
    }

    /**
     * 获取排班信息表详细信息
     *
     * @param scheduleId 主键
     */
    // @SaCheckPermission("nursing:staffSchedule:query")
    @GetMapping("/{scheduleId}")
    public R<StaffScheduleVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long scheduleId) {
        return R.ok(staffScheduleService.queryById(scheduleId));
    }

    /**
     * 新增排班信息表
     */
    // @SaCheckPermission("nursing:staffSchedule:add")
    @Log(title = "排班信息表", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody StaffScheduleBo bo) {
        return toAjax(staffScheduleService.insertByBo(bo));
    }

    /**
     * 修改排班信息表
     */
    // @SaCheckPermission("nursing:staffSchedule:edit")
    @Log(title = "排班信息表", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody StaffScheduleBo bo) {
        return toAjax(staffScheduleService.updateByBo(bo));
    }

    /**
     * 删除排班信息表
     *
     * @param scheduleIds 主键串
     */
    // @SaCheckPermission("nursing:staffSchedule:remove")
    @Log(title = "排班信息表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{scheduleIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] scheduleIds) {
        return toAjax(staffScheduleService.deleteWithValidByIds(List.of(scheduleIds), true));
    }
}
